package com.henu.engineer.controller.teacher.cl

import com.alibaba.fastjson.JSONObject
import com.henu.engineer.StringUtils
import com.henu.engineer.service.teacher.cl.CourseGroupCLService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

/**
 *
 * @author noexcept
 * @since 2021/8/13 10:50
 */
@RestController
@RequestMapping("/cl")
class CourseGroupCLController {

    @Autowired
    lateinit var courseGroupCLService: CourseGroupCLService

    /**
     * 为某个课程组新添一名成员
     */
    @PostMapping("/courseGroupMember")
    fun courseGroupMember(@RequestBody jsonObject: JSONObject?): String? {
        val res = JSONObject()
        if (jsonObject == null) {
            res["code"] = 1
            res["msg"] = "参数缺失"
            return res.toJSONString()
        }
        val courseGroupId = jsonObject["courseGroupId"] as String
        val teacherId = jsonObject["teacherId"] as String
        if (StringUtils.isEmpty(courseGroupId, teacherId)) {
            res["code"] = 2
            res["msg"] = "参数缺失"
            return res.toJSONString()
        }
        if (courseGroupCLService.addCourseGroupMember(courseGroupId!!, teacherId!!)) {
            res["code"] = 0
            res["msg"] = "添加成功"
        } else {
            res["code"] = 3
            res["msg"] = "添加失败"
        }
        return res.toJSONString()
    }

}